﻿using NUnit.Framework;
using Microsoft.WowAddonStudio.FrameXml.Serialization.Support;

namespace Microsoft.WowAddonStudio.FrameXml.Serialization.Tests
{
    [TestFixture]
    public class ComplexInheritanceTest : FrameXmlDirectoryTestBase
    {
        [Test]
        public void FontHeightInheritanceTest()
        {
            // Create MasterFont from Fonts.xml
            var masterFont = new Font
                                 {
                                     Name = "MasterFont",
                                     Virtual = true,
                                     Shadow = new Shadow
                                                  {
                                                      Offset = new Dimension
                                                                   {
                                                                       AbsDimension = new AbsDimension
                                                                                          {
                                                                                              X = 1,
                                                                                              Y = -1
                                                                                          }
                                                                   },
                                                      Color = new Color { Red = 0f, Green = 0f, Blue = 0f }
                                                  }
                                 };

            // Create GameFontNormal from Fonts.xml
            var gameFontNormal = new Font
                                     {
                                         Name = "GameFontNormal",
                                         Inherits = "MasterFont",
                                         TrueTypeFont = @"Fonts\FRIZQT__.TTF",
                                         Virtual = true,
                                         FontHeight = new FontHeight
                                                          {
                                                              Value = 12
                                                          },
                                         Color = new Color { Red = 1.0f, Green = 0.82f, Blue = 0f }
                                     };

            // Create font that inherits from GameFontNormal
            var myFont = new Font
                             {
                                 Name = "MyFont",
                                 Inherits = "GameFontNormal"
                             };
            
            // Assert number of virtual FrameXML objects registered
            Assert.AreEqual(2, FrameXmlDirectory.Default.Count);

            // Assert object inheritance hierarchy
            Assert.AreSame(masterFont, gameFontNormal.InheritedObject);
            Assert.AreEqual(gameFontNormal, myFont.InheritedObject);

            // Assert all parameters inherited or otherwise

            // Assert default values
            Assert.AreEqual(false, myFont.Virtual);
            Assert.AreEqual(JustifyHorizontal.Center, myFont.JustifyHorizontal);

            // Assert simple values
            Assert.AreEqual(@"Fonts\FRIZQT__.TTF", myFont.TrueTypeFont);

            // Assert complex values
            Assert.AreEqual(1, myFont.Shadow.Offset.AbsDimension.X);
            Assert.AreEqual(-1, myFont.Shadow.Offset.AbsDimension.Y);

            Assert.AreEqual(1.0f, myFont.Color.Alpha); // Default from Color type
            Assert.AreEqual(1.0f, myFont.Color.Red);
            Assert.AreEqual(0.82f, myFont.Color.Green);
            Assert.AreEqual(0f, myFont.Color.Blue);

            Assert.AreEqual(12, myFont.FontHeight.Value);
        }
    }
}
